<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加多张图片</title>
    <script src="asserts/js/jquery-2.1.1.min.js"></script>

</head>
<script>
    $(function () {
        $('#file').on("change", function () {
            var formData = new FormData();
            for (var i = 0; i < $("#file")[0].files.length; i++) {  //循环获取上传个文件
                formData.append("file", $("#file")[0].files[i]);
            }
            $.ajax({
                "url": "/taobei_web/pro/upload", // 上传地址
                "data": formData,
                "dataType": "json",
                "type": "post",
                "contentType": false, //上传文件一定要是false
                "processData": false,
                "success": function (obj) {
                    debugger;
                    if (obj.status == 200) {
                        let text = "";
                        for (let i = 0; i < obj.data.length; i++) {
                            text += "<div><img src=" + obj.data[i] + "></div>"
                        }
                        $("#img").html(text)
                    }
                }
            });
        })
        let flag;
            $("#but").click(function () {
                if($("#img").text()==null||$("#img").text().length==0){
                    $.ajax({
                        url:'/taobei_web/pro/addProduct',
                        type:'put',
                        dataType:'json',
                        success(res){
                            alert(res.msg);
                            flag=true;
                        }
                    })
                }
                else{
                    alert("请选择图片");
                    flag=false
                }
            })
    })

</script>
<style>

    #img div{
        float: left;
        margin: 20px;
        width:100px ;
    }
    #img div img{
        width: 100%;
    }
</style>
<body>
<div class="item">
    <div id="time"></div>
    <input type="file" name="files" id="file" multiple="multiple" accept="image/png,image/jpg,image/gif,image/JPEG">
    <div id="img">

    </div>
    <input type="button" id="but" value="上传">
</div>


</body>

</html>